'use strict';

var path = require('path');
var HtmlwebpackPlugin = require('html-webpack-plugin');
var ROOT_PATH = path.resolve(__dirname);
var srcDir = path.resolve(ROOT_PATH, 'src');
var BUILD_PATH = path.resolve(ROOT_PATH, 'assets');
var cssDir = path.resolve(ROOT_PATH, 'src/css');
var antdDir = path.resolve(ROOT_PATH, 'node_modules/antd');
var pak = require('./package.json');
module.exports= {
  entry: {
    app: path.resolve(srcDir, 'app.jsx'),
    vendors:['react','react-dom','redux','react-redux','react-router','react-router-redux','redux-thunk','redux-logger']
  },
  output: {
    path: BUILD_PATH,
    filename: '[name].js' ,
    chunkFilename: 'js/[name].chunk.js'
  },
  //enable dev source map
  devtool: 'eval-source-map',
  //enable dev server
  devServer: {
    historyApiFallback: true,
    hot: true,
    inline: true,
    progress: true
  },
  //babel重要的loader在这里
  module: {
    loaders: [
      {
        test: /\.js|jsx$/,
        loader: 'babel',
        include: srcDir
      },
      {
        test: /\.css?$/,
        loader: 'style!css',
        include: [antdDir,cssDir]
      },
      {
        test: /\.less?$/,
        loader: 'style!css!less',
        include: srcDir
      },
      {
        test: /\.scss?$/,
        loader: 'style!css!sass'
      },
      {
        test: /\.png|.gif$/,
        loader: 'url',
        include: srcDir
      },
      {
        test: /\.svg|woff|eot|ttf$/,
        loader: require.resolve('file-loader') + '?name=[path][name].[ext]'
      }
    ],
    postLoaders: [
      {
        test: /\.jsx?$/,
        loaders: ['es3ify-loader']
      }
    ]
  },
  resolve: {
    extensions: ['', '.js','.jsx', '.css','.less', '.tpl', '.png', '.jpg', '.gif']
  },
  plugins: [
    new HtmlwebpackPlugin({
      title: pak.description,
      filename: 'index.html',
      inject: 'body',
      chunks: ['app','vendors'],
      template: './src/tmpl/main.html'
    })
  ]
};
/**
 * branch:0.2 ENV_development
 * */